package generics;


public class Test
{
  /**
   * @param args
   */
  @SuppressWarnings("unchecked")
  public static void main(String[] args)
  {
    ClassXXX xxx = new ClassXXX();
    ClassZZZ zzz = new ClassZZZ();   
    
    findCategory(xxx);
    findCategory(zzz);
  }
  
  
  @SuppressWarnings("unchecked")
  public static <T extends Interface1 & Category> void findCategory(T component)
  {
    Class<? extends Category> type = null;
   
    System.out.println();
    System.out.println("*** " + component.getClass().getSimpleName() + " ***");
    Class<?>[] interfaces = component.getClass().getInterfaces();
    for (Class<?> i: interfaces)
    {
      Class<?>[] iis = i.getInterfaces();
      System.out.println("Interface: " + i.getSimpleName());
      for (Class<?> ii: iis)
        System.out.println("  " + ii.getSimpleName());
      
      for (Class<?> ii: iis)
      {
        if (ii == Category.class)
          type = (Class<? extends Category>)i;
      }
    }
    
    if (type == null)
    {
      System.out.println("ERROR!!  Category is null!");
      return;
    }
    
    System.out.println();
    System.out.println("Category: " + type.getSimpleName());
  }
   
}
